<?php
/**
 * @author: wuwenhan <329576084@qq.com>
 * @copyright 综合管理系统
 * @link http://www.zhongkefu.com
 */

namespace zhongkefu\helpers;

use zhongkefu\zhongkefu;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;

class WanhuCaptcha extends \yii\captcha\CaptchaAction
{
    public $flag;
    /**
     * Generates a new verification code.
     * @return string the generated verification code
     */
    public function generateVerifyCode()
    {
        if ($this->minLength > $this->maxLength) {
            $this->maxLength = $this->minLength;
        }
        if ($this->minLength < 3) {
            $this->minLength = 3;
        }
        if ($this->maxLength > 20) {
            $this->maxLength = 20;
        }
        $length = mt_rand($this->minLength, $this->maxLength);

        $letters = 'bcdfghjklmnpqrstvwxyz';
        $vowels = 'aeiou';
		$charone = '1234567890';
		$chartwo = 'abcdefghijklmnopqrstuvwxyz1234567890';
        $code = '';
        for ($i = 0; $i < $length; ++$i) {
			if($this->flag=='letter'){
				if ($i % 2 && mt_rand(0, 10) > 2 || !($i % 2) && mt_rand(0, 10) > 9) {
					$code .= $vowels[mt_rand(0, 4)];
				} else {
					$code .= $letters[mt_rand(0, 20)];
				}
			}elseif($this->flag == 'numb'){
				$code .= $charone[mt_rand(0, 9)];
			}elseif($this->flag == 'hunhe'){
				$code .= $chartwo[mt_rand(0, 35)];
			}
        }
        return $code;
    }

}